﻿using System;
using System.Text;

namespace YanZhiwei.DotNet2.Utilities.Common
{
    /// <summary>
    /// Base64帮助类
    /// </summary>
    public static class Base64Helper
    {
        #region  Base64编码
        /// <summary>
        /// Base64编码
        /// </summary>
        /// <param name="data">需要编码字符串</param>
        /// <returns>Base64编码字符串</returns>
        public static string Base64Encode(this string data)
        {
            if (!string.IsNullOrEmpty(data))
                return Convert.ToBase64String(Encoding.UTF8.GetBytes(data));
            return data;

        }
        #endregion
        #region  Base64 解码
        /// <summary>
        /// Base64 解码
        /// </summary>
        /// <param name="data">需要解码的字符串</param>
        /// <returns>Base64解码字符串</returns>
        public static string Base64Decode(this string data)
        {
            if (!string.IsNullOrEmpty(data))
                return Encoding.UTF8.GetString(Convert.FromBase64String(data));
            return data;
        }
        #endregion
    }
}
